import request from '@/utils/request'

// 1、条件查询角色分页列表
export const GetRolePage = (pageNum, pageSize, keyword) => {
  return request({
    url: `/admin/system/role/list/${pageNum}/${pageSize}`,
    method: 'GET',
    // params/data/headers配置参数时 值必须是json对象
    params: { keyword: keyword }, //url?keyword='xxxx'
  })
}
// 2、查询所有角色
export const GetRoles = () => {
  return request({
    url: `/admin/system/role/list`,
    method: 'GET',
  })
}
// 3、id查询角色
export const GetRoleById = id => {
  return request({
    url: `/admin/system/role/getById/${id}`,
    method: 'GET',
  })
}
// 4、更新角色
export const UpdateRole = role => {
  return request({
    url: `/admin/system/role/update`,
    method: 'PUT',
    data: role,
  })
}
// 5、根据id删除角色
export const DeleteRole = id => {
  return request({
    url: `/admin/system/role/delete/${id}`,
    method: 'DELETE',
  })
}
// 6、新增角色
export const SaveRole = role => {
  return request({
    url: `/admin/system/role/save`,
    method: 'POST',
    data: role,
  })
}
// 7、查询所有角色和用户已分配角色
export const GetRolesAndIsChecked = userId => {
  return request({
    url: `/admin/system/role/listAllRolesAndIsChecked/${userId}`,
    method: 'GET',
  })
}
// 8、给角色分配菜单
export const AssignMenus2Role = (roleId, menuIds) => {
  return request({
    url: `/admin/system/role/assignMenus2Role/${roleId}`,
    method: 'PUT',
    data: menuIds,
  })
}
